import {combineReducers} from 'redux';
import {Store} from '../../enums/constant';

const initMainStoreState = {
  // 在这里给 Main 赋初值
  person: {},
  isLogin: '', //是否登录
};

const initIsLoading = {
  // 在这里给 IsLoading 赋初值
  isLoadingStatus: 'false', //是否下载完成
};

const MainStore = (
  state = initMainStoreState,
  action: {
    type: String;
    isLogin?: String;
    person?: {phone: String; passworde: String};
  },
) => {
  console.log('MainStore:fff', state, action.type);
  console.log(action.type);
  switch (action.type) {
    case Store.REGISTRE_STORE:
      return {
        ...state,
        isLogin: action.isLogin,
        person: action.person,
        token: action.token,
      };
    // case Store.BACKLOGIN_STORE:
    //   return {...initMainStoreState}; // 返回 initState，而不是 { initState }
    default:
      return state;
  }
};

const IsloadingReducer = (
  state = initIsLoading,
  action: {
    type: String;
    isLoadingStatus: String;
  },
) => {
  console.log('IsloadingReducerfff:', state);
  console.log(action.type);
  switch (action.type) {
    case Store.DOWNLOAD_STORE:
      return {
        ...state,
        isLoadingStatus: action.isLoadingStatus,
      };
    default:
      return state;
  }
};

export const rootReducer = combineReducers({
  MainStore: MainStore, // 注意这里的键名 'MainStore' 对应你的 reducer 函数
  IsloadingReducer: IsloadingReducer, // 键名 'IsloadingReducer' 对应你的 reducer 函数
});
